package com.lfd.rabbitmq;

import com.lfd.rabbitmq.service.DirectMessageProducer;
import com.lfd.rabbitmq.service.MessageProducer;
import com.lfd.rabbitmq.service.NewMessageProducer;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Date;

@EnableRabbit
@SpringBootApplication
public class RabbitmqApplication implements CommandLineRunner {
    @Autowired
    private MessageProducer messageProducer;
    @Autowired
    private NewMessageProducer newMessageProducer;
    @Autowired
    private DirectMessageProducer directMessageProducer;

    public static void main(String[] args) {
        SpringApplication.run(RabbitmqApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
//        // 发送测试消息
//        messageProducer.sendMessage("Hello, RabbitMQ!");
//        messageProducer.sendMessageWithReturn("Hello with Return!"+new Date());

        // 发送测试消息
//        newMessageProducer.sendMessage("发送测试消息"+new Date());
        // 发送测试消息
        directMessageProducer.sendMessage("发送死信消息" + new Date());
    }
}
